import { useEffect } from 'react'
import Taro from '@tarojs/taro'
import { Request,setGlobalData} from './util'
import {Provider} from 'react-redux'
import './app.less'
import Store from './store'

export default function App(props)
{
    const domain = 'https://www.henrywong01.top'
    setGlobalData('domain',domain);

   
    useEffect(()=>{
        //小程序登录
        Taro.login({
            success: res => {
                console.log("code值为"+res.code);
                //服务端登录请求获取用户openid
                Request(domain + "/client/user/onLogin",{code: res.code }).then((result)=>{
                    const {openid, session_key} = result.data.data;
                    Taro.setStorageSync("openid",openid); //储存openid
                    Taro.setStorageSync("session_key",session_key);
                });
            }
        })
    },[]);
    
    return (
        <Provider store={Store}>
            {props.children}
        </Provider>
            
       
    )
}
